package com.aaa.base.service.impl;

import com.aaa.base.mapper.CommodityMapper;
import com.aaa.base.service.CommodityService;
import com.aaa.entity.base.Commodity;
import com.aaa.vo.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-23
 */
@Service
public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity> implements CommodityService {

    @Autowired
    private CommodityMapper commodityMapper;

    /**
    * @Description: 按条件分页查询 //描述
    * @Param: [page（页数）, size（一页几条数据）, commodity（传入条件类）]//参数
    * @return: com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.aaa.base.entity.Commodity>
    * @Author: 岚氓//作者
    * @Date: 2020/11/27  10:12
    */
    @Override
    public Page<Commodity> findCommodityPage(Integer page, Integer size, Commodity commodity) {
        Page<Commodity> pageinfo=new Page<>(page,size);
        String bar=commodity.getBar();//条码
        String name=commodity.getName();//商品名
        String alias=commodity.getAlias();//别名
        QueryWrapper<Commodity> queryWrapper=new QueryWrapper<>();//查询条件类
        if (StringUtils.isNotEmpty(bar)){
            queryWrapper.like("bar",bar);
        }
        if (StringUtils.isNotEmpty(name)){
            queryWrapper.like("name",name);
        }
        if (StringUtils.isNotEmpty(alias)){
            queryWrapper.like("alias",alias);
        }
        queryWrapper.eq("warehouseid",41L);
        return this.commodityMapper.selectPage(pageinfo, queryWrapper);
    }

    @Override
    public List<Map> selectComBarNamByWareId(Long warehouseid) {
        return commodityMapper.selectComBarNamByWareId(warehouseid);
    }


}
